import * as type from './type'
import axios from 'axios'
import qs from 'querystring'

const state = {
    list:null
}

export const actionCreators = {
    banner (a) {
        // console.log('1111111111',a)
        const idstr =  qs.parse(a.search.slice(1))
        return dispatch => {
            axios({
                url:'/api/getMemberAboutInfo',
                params:{
                    goods_id: idstr.goods_id,
                    sa_id: 22880199,
                    is_pt_goods: 0,
                    req_coupons_id: idstr.goods_id,
                }
            })
            .then(data=>{
                const goodsdata = data.data.skudata
                const discountdata = data.data.discount
                const action = {
                    type:type.LUNBO,
                    payload:[goodsdata,discountdata]
                }
                dispatch(action)
            })
            .catch(error=>console.log(error))
        }
    }
}

export const reducer = (previousState = state ,action ) => {
    const newState = {
        ...previousState
    }

    switch (action.type) {
        case type.LUNBO:
            newState.details = action.payload
            break;
    
        default:
            break;
    }
    return newState
}